from random import choice,randint

from bullet import Bullet
from tank import Tank

images_path = "./images/"
ey_tank_u = images_path + "EU.gif"
ey_tank_D = images_path + "ED.gif"
ey_tank_L = images_path + "EL.gif"
ey_tank_r = images_path + "ER.gif"


class EnemyTank(Tank):
    def __init__(self, left, top):
        super().__init__(ey_tank_u, ey_tank_D, ey_tank_L, ey_tank_r, left, top)
        # self.speed = 1,
        self.direction = self.rand_direction()
        # self.image = self.images[self.direction]
        # 坦克所在区域
        # self.rect = self.image.get_rect()
        # 坦克初始化位置
        self.rect.left = self.rand_rect_limit(left - self.rect.width)
        self.rect.top = self.rand_rect_limit(top - self.rect.height)
        # self.stop = True
        # 新增随机步数
        self.step = 20
        self.speed = randint(1,2)

    def rand_direction(self):
        return choice(['U', 'D', 'L', 'R'])

    def rand_rect_limit(self,limit):
        return randint(0,limit)

    def rand_move(self,screen_width,screen_height):
        if self.step <= 0:
            self.direction = self.rand_direction()
            self.step = self.rand_rect_limit(100)
        else:
            self.move(screen_width,screen_height)
            self.step -= 1

    def shot(self):
        num = randint(1,50)
        if num == 5:
            return Bullet(self)